
cat << EOF > $K8_CONFIG_HOME/kube-apiserver
KUBE_APISERVER_OPTS="--logtostderr=true \
    --v=4 \
    --etcd-servers=$K8_ETCD_SERVERS \
    --bind-address=$K8_HOST \
    --secure-port=6443 \
    --advertise-address=$K8_HOST \
    --allow-privileged=true \
    --service-cluster-ip-range=$K8_SERVICE_CLUSTER_IP_RANGE \
    --enable-admission-plugins=NamespaceLifecycle,LimitRanger,ServiceAccount,ResourceQuota,NodeRestriction \
    --authorization-mode=RBAC,Node \
    --enable-bootstrap-token-auth \
    --token-auth-file=$K8_CONFIG_HOME/token.csv \
    --service-node-port-range=30000-50000 \
    --tls-cert-file=$K8_CERT_HOME/kube-server.pem  \
    --tls-private-key-file=$K8_CERT_HOME/kube-server-key.pem \
    --client-ca-file=$K8_CERT_HOME/kube-ca.pem \
    --service-account-key-file=$K8_CERT_HOME/kube-ca-key.pem \
    --etcd-cafile=$K8_CERT_HOME/etcd-ca.pem \
    --etcd-certfile=$K8_CERT_HOME/etcd-server.pem \
    --etcd-keyfile=$K8_CERT_HOME/etcd-server-key.pem"


EOF

currentPath=$(pwd)
cat << EOF > $currentPath/build/service/kube-apiserver.service
[Unit]
Description=Kubernetes API Server
Documentation=https://github.com/kubernetes/kubernetes
 
[Service]
EnvironmentFile=$K8_CONFIG_HOME/kube-apiserver
ExecStart=$K8_SERVER_BIN/kube-apiserver \$KUBE_APISERVER_OPTS
Restart=on-failure
 
[Install]
WantedBy=multi-user.target


EOF


sed -i '/kube-apiserver/d' $K8_MASTER_SHELL

sed -i "/daemon-reload/i\cp $currentPath/build/service/kube-apiserver.service $K8_SERVICE_HOME/" $K8_MASTER_SHELL

sed -i "/enable kube-apiserver/d" $K8_MASTER_SHELL

sed -i "/start kube-apiserver/d" $K8_MASTER_SHELL

echo "systemctl enable kube-apiserver" >> $K8_MASTER_SHELL

echo "systemctl stop kube-apiserver" >> $K8_MASTER_SHELL

echo "systemctl start kube-apiserver" >> $K8_MASTER_SHELL

checkShell=$currentPath/build/api-server-check.sh

echo "#check api-server " > $checkShell

chmod +x $checkShell

echo "ps -ef | grep kube-apiserver " >> $checkShell
echo "netstat -tulpn | grep kube-apiserve " >> $checkShell
